package cn.zh.base.dto;


import cn.zh.base.util.MD5Utils;
import cn.zh.base.util.StrUtils;
import cn.zh.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
public class PhoneRegisterDto {
    @NotNull(message = "电话号码不能为空")
    private String phone;
    @NotNull(message = "uuid不能为空")
    // uuid
    private String imageCodeKey;
    @NotNull(message = "图形验证码不能为空")
    // 图形验证码
    private String imageCodeValue;
    @NotNull(message = "手机号验证码不能为空")
    // 手机号验证码
    private String phoneCode;
    @NotNull(message = "密码不能为空")
    // 密码
    private String password;
    @NotNull(message = "确认密码不能为空")
    // 确认密码
    private String passwordRepeat;

    private String type;


    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        /// todo 盐值 + 密码
        String pw = MD5Utils.encrypByMd5(salt + this.password);
        return User
                .builder()
                .createtime(new Date())
                .salt(salt)
                .password(pw)
                .state(1)
                .phone(this.phone)
                .username(this.phone)
                .build();
    }

}
